package se.krutstampen.backend.infrastructure;

import java.io.File;

import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import se.krutstampen.backend.domain.model.product.Firmware;
import se.krutstampen.backend.domain.model.product.Group;
import se.krutstampen.backend.domain.model.product.OperatingSystem;
import se.krutstampen.backend.domain.model.product.Product;


@Singleton
@Startup
public class DataLoader {
	
	private static final String WIN7 = "Windows 7";
	private static final String WIN7_64 = "Windows 7 64";
	private static final String LINUX = "Linux";
	private static final String MACOS = "Mac OS";

	@PersistenceContext
	EntityManager entityManager;
	
	@PostConstruct
	public void init(){
		
		//Create all OS
		OperatingSystem osWin7 = new OperatingSystem(WIN7);
		OperatingSystem osWin7_64 = new OperatingSystem(WIN7_64);
		OperatingSystem osLinux = new OperatingSystem(LINUX);
		OperatingSystem osMacOs = new OperatingSystem(MACOS);
		
		entityManager.persist(osWin7);
		entityManager.persist(osWin7_64);
		entityManager.persist(osLinux);
		entityManager.persist(osMacOs);
		
		Firmware firmware1 = new Firmware.Builder()
								.setFile(new File("c:/tmp/Desert.jpg"))
								.setName("XWWW-CVD123")
								.setOperatingSystem(osWin7_64)
								.build();
		entityManager.persist(firmware1);

		Firmware firmware2 = new Firmware.Builder()
				.setFile(new File("c:/tmp/Desert.jpg"))
				.setName("XWWW-CVD12322")
				.setOperatingSystem(osWin7)
				.build();
		entityManager.persist(firmware2);
		
		Group groupGarden = new Group();
		groupGarden.setName("TRÄDGÅRD");
		entityManager.persist(groupGarden);		

		Group groupForest = new Group();
		groupForest.setName("SKOG");
		entityManager.persist(groupForest);		
		
		Product product1 = new Product();
		product1.setGroup(groupGarden);
		product1.setName("AUTOMOWER");
		
		product1.addFirmware(firmware1);
		
		
		entityManager.persist(product1);
		
		
	}
}
